package com.ruoyi.fullminusgiveaway.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.fullminusgiveaway.domain.Goods;
import com.ruoyi.fullminusgiveaway.domain.Vo.fullGoods;
import com.ruoyi.fullminusgiveaway.service.fullminusService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.fullminusgiveaway.domain.FullMinusGiveaway;
import com.ruoyi.fullminusgiveaway.service.IFullMinusGiveawayService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 满减满送活动Controller
 *
 * @author ruoyi
 * @date 2024-11-14
 */
@RestController
@RequestMapping("/minus")
public class fullminusController extends BaseController
{
    @Autowired
    private fullminusService fullMinusGiveawayService;

    /**
     * 查询满送活动列表
     */
    @RequiresPermissions("fullminus:minus:listMinus")
    @GetMapping("/list")
    public TableDataInfo list(String goodsName, String reduceMoney, String businessName, String shopName)
    {
        startPage();
        List<FullMinusGiveaway> list = fullMinusGiveawayService.selectFullMinusGiveawayListMinus(goodsName,reduceMoney,businessName,shopName);
        return getDataTable(list);
    }

    /**
     * 查询商品列表
     * @return
     */
    @GetMapping("/MinusGoodsList")
    public TableDataInfo goodsList()
    {
        List<Goods> list = fullMinusGiveawayService.goodsList();
        return getDataTable(list);
    }

    /**
     * 导出满减满送活动列表
     */
    @RequiresPermissions("fullminus:minus:exportMinus")
    @Log(title = "满减满送活动", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response,String goodsName, String reduceMoney, String businessName, String shopName)
    {
        List<FullMinusGiveaway> list = fullMinusGiveawayService.selectFullMinusGiveawayListMinus(goodsName,reduceMoney,businessName,shopName);
        ExcelUtil<FullMinusGiveaway> util = new ExcelUtil<FullMinusGiveaway>(FullMinusGiveaway.class);
        util.exportExcel(response, list, "满减满送活动数据");
    }

    /**
     * 获取满减满送活动详细信息
     */
    @RequiresPermissions("fullminus:minus:queryMinus")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(fullMinusGiveawayService.selectFullMinusGiveawayByIdMinus(id));
    }

    /**
     * 新增满减满送活动
     */
    @RequiresPermissions("fullminus:minus:addMinus")
    @Log(title = "满减满送活动", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody fullGoods full)
    {
        Long goodsId = (long) fullMinusGiveawayService.selectAddGoodsName(full.getGoods().getGoodsName());
        full.setMinusGoodsId(goodsId);
        return toAjax(fullMinusGiveawayService.insertFullMinusGiveawayMinus(full));
    }

    /**
     * 修改满减满送活动
     */
    @RequiresPermissions("fullminus:minus:edit")
    @Log(title = "满减满送活动", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody fullGoods fullGoods)
    {
        return toAjax(fullMinusGiveawayService.updateFullMinusGiveawayMinus(fullGoods));
    }

    /**
     * 删除满减满送活动
     */
    @RequiresPermissions("fullminus:minus:removeMinus")
    @Log(title = "满减满送活动", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(fullMinusGiveawayService.deleteFullMinusGiveawayByIdsMinus(ids));
    }
}
